package com.Ling.Thread.sync;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/**
 * File Name: AsyncDemo
 * Date: 2020-06-29 15:53
 * Author: liangling
 * Description 使用注解创建线程
 */
@Component
@Slf4j
public class AsyncDemo {

    @Async
    public void async() {
        log.info("异步任务开始执行");
        System.out.println("异步任务线程名称是：" + Thread.currentThread().getName());
        System.out.println("这是一个异步任务");

    }

}














//    @Async
//    public Future<String> futureAsync() throws InterruptedException {
//        log.info("异步任务开始执行");
//        log.info("异步任务线程名字："+Thread.currentThread().getName());
//        Thread.sleep(2000);
//        return new AsyncResult<String>("the Async task was running");
//    }
